package com.shopx.oss.controller;

import com.shopx.base.anno.RepearSubmitChkAnno;
import com.shopx.base.dto.Result;
import com.shopx.base.utils.ResultUtil;
import com.shopx.core.common.CommonConstant;
import com.shopx.oss.service.IFileService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件上传
 *
 * @author:lituo
 * @date:2021/12/12
 **/
@RestController
@RequestMapping(value = "/fileController")
public class FileController {

  @Resource
  private IFileService fileService;

//  @Resource
//  private IAliyunOssService aliyunOssService;

  /**
   * 上传文件
   *
   * @param file
   * @return java.lang.String
   * @author lituo
   * @date 6:13 PM 2021/12/12
   */
  @PostMapping("/uploadFile")
  @ResponseBody
  public Result<String> uploadFile(@RequestParam("file") List<MultipartFile> file, String cpId) throws Exception {
    String filePath = fileService.uploadFile(file, CommonConstant.FileType.FILE, cpId);
    return ResultUtil.ok(filePath);
//    String filePath = aliyunOssService.uploadFile(file, CommonConstant.FileType.FILE, cpId);
//    return ResultUtil.ok(filePath);
  }

  /**
   * 上传CAD
   *
   * @param file
   * @param cpId
   * @return com.shopx.base.dto.Result<java.lang.String>
   * @auth lituo
   * @date 6.3.23 6:41 下午
   **/
  @PostMapping("/uploadCad")
  @ResponseBody
  public Result<String> uploadCad(@RequestParam("file") List<MultipartFile> file, String cpId) throws Exception {
    String filePath = fileService.uploadFile(file, CommonConstant.FileType.CAD, cpId);
    return ResultUtil.ok(filePath);
  }

  /**
   * 上传图片
   *
   * @param file
   * @return java.lang.String
   * @author lituo
   * @date 6:14 PM 2021/12/12
   */
  @PostMapping("/uploadImg")
  @ResponseBody
  public Result<String> uploadImg(@RequestParam("img") List<MultipartFile> file, String cpId) throws Exception {
    String filePath = fileService.uploadFile(file, CommonConstant.FileType.IMG, cpId);
    return ResultUtil.ok(filePath);
//    String filePath = aliyunOssService.uploadFile(file, CommonConstant.FileType.IMG, cpId);
//    return ResultUtil.ok(filePath);
  }

  /**
   * 上传cad
   * @author lituo
   * @date 6:14 PM 2021/12/12
   * @param  file
   * @return java.lang.String
   */
//  @RequestMapping("/uploadCad")
//  @ResponseBody
//  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)   public Result<String> uploadCad(@RequestParam("cad") List<MultipartFile> file,String cpId) throws Exception {
//    String filePath = fileService.uploadFile(file, CommonConstant.FileType.CAD,cpId);
//    return ResultUtil.ok(filePath);
//  }


  /**
   * 上传工地核心文件（设计图纸，签字合同，客户签字选材单，客户签字预算）
   *
   * @param file
   * @param cpId
   * @return com.shopx.base.dto.Result<java.lang.String>
   * @auth lituo
   * @date 6.3.23 6:37 下午
   **/
  @PostMapping("/uploadProjImg")
  @ResponseBody
  public Result<String> uploadProjImg(@RequestParam("img") List<MultipartFile> file, String cpId) throws Exception {
    String filePath = fileService.uploadFile(file, CommonConstant.FileType.COREIMG, cpId);
    return ResultUtil.ok(filePath);
  }

}



